<div class="form-group pull-right">
  <pfng-toast-notification-list [notifications]="notifications" (onCloseSelect)="handleCloseNotification($event)"
    [showClose]="true">
  </pfng-toast-notification-list>
</div>

<h1>
  Import Jobs
  <div class="pull-right" *ngIf="canImportArtifact()">
    <button class="btn btn-default" (click)="openArtifactUploader()">
      <span class="fa fa-upload"></span> Upload
    </button>&nbsp;
    <button class="btn btn-primary" (click)="createImportJob()">
      <span class="fa fa-plus"></span> Create
    </button>
  </div>
</h1>
<small>Importers periodically scan source code repositories to check for update in your Services and API mock
  definitions.</small>

<div class="container-fluid">
  <div id="pf-list-standard" class="list-group list-view-pf list-view-pf-view">
    <div class="toolbar-pf">
      <div class="col-sm-12">
        <pfng-toolbar [config]="toolbarConfig" (onFilterChange)="handleFilter($event)"></pfng-toolbar>
      </div>
    </div>
    <div *ngFor="let job of importJobs" class="list-group-item">
      <div class="list-view-pf-main-info">
        <div class="list-view-pf-body">
          <div class="list-view-pf-description">
            <div class="list-group-item-heading">
              {{ job.name }}
            </div>
            <div class="list-group-item-text repositoryUrl">
              <a href="{{ job.repositoryUrl }}">{{ job.repositoryUrl }}</a><br />
              <app-label-list [metadata]="job.metadata" [filter]="repositoryFilterFeatureLabelList()"></app-label-list>
              <div *ngIf="job.metadata" class="job-update">
                <small>Updated on {{ job.metadata.lastUpdate | date : 'medium' }}</small>
              </div>
            </div>
          </div>
          <div class="list-view-pf-additional-info">
            <div class="list-view-pf-additional-info-item">
              <span *ngIf="!job.mainArtifact" class="pficon pficon-resources-almost-empty"
                tooltip="Secondary artifact"></span>
              <span *ngIf="job.secretRef != null" class="pficon pficon-locked"
                tooltip="Using {{ job.secretRef.name }} secret"></span>
            </div>
            <div class="list-view-pf-additional-info-item">
              <span class="label label-info" *ngIf="job.lastImportDate">Imported</span>
              <span class="label label-default" *ngIf="!job.lastImportDate">Not Imported</span>
              <span class="label label-success" *ngIf="job.active">Scanned</span>
              <span class="label label-primary" *ngIf="!job.active">Not scanned</span>
              <span class="label label-danger" *ngIf="job.lastImportError" tooltip="{{ job.lastImportError }}"
                placement="top">
                Import Error
              </span>
              <span class="label label-warning" *ngIf="job.serviceRefs">
                <a (click)="openServiceRefs(job.serviceRefs)">Services</a>
              </span>
            </div>
          </div>
        </div>
      </div>

      <div class="list-view-pf-actions">
        <div class="dropdown pull-right dropdown-kebab-pf" dropdown *ngIf="hasRole('admin') || hasRoleForJob('manager', job)">
          <button id="dropdownKebabRight" class="btn btn-link dropdown-toggle" type="button" dropdownToggle aria-controls="dropdown-actions"
            aria-haspopup="true" aria-expanded="true">
            <span class="fa fa-ellipsis-v"></span>
          </button>
          <ul id="dropdown-actions" class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownKebabRight">
            <li><a (click)="editImportJob(job)">Edit</a></li>
            <li><a (click)="confirmDeleteDialog.open(job)">Delete</a></li>
            <li role="separator" class="divider"></li>
            <li><a (click)="activateImportJob(job)" *ngIf="!job.active">Activate</a></li>
            <li><a (click)="startImportJob(job)" *ngIf="job.active">Force import</a></li>
            <li><a (click)="stopImportJob(job)" *ngIf="job.active">Stop</a></li>
          </ul>
        </div>
      </div>
    </div>
  </div>

  <pfng-pagination [config]="paginationConfig" (onPageNumberChange)="handlePageNumber($event)"
    (onPageSizeChange)="handlePageSize($event)">
  </pfng-pagination>
</div>

<app-confirm-delete-dialog #confirmDeleteDialog (delete)="deleteImportJob($event)">
  <p>Do you really want to delete the selected Import Job ?</p>

  <div class="alert alert-danger">
    <span class="pficon pficon-error-circle-o"></span>
    <strong>NOTE : </strong>
    <span>This will <strong>permanently</strong> delete the Import Job from Microcks. Already discovered Services &amp;
      APIs remain but will not be updated. This operation cannot be undone.</span>
  </div>
</app-confirm-delete-dialog>